package scuts.core;

import scuts.core.types.Option;
import scuts.core.types.LazyIterator;

class FindIndexIterable 
{

  public static function findIndex<T>(iter:Iterable<T>, f:T->Bool):Option<Int>
  {
    return FindIndexIterator.findIndex(iter.iterator(), f);
  }
  
}

class FindIndexIterator 
{

  public static function findIndex<T>(iter:Iterator<T>, f:T->Bool):Option<Int>
  {
    var z = 0;
    for (i in iter) {
      if (f(i)) return Some(z);
      z++;
    }
    return None;
  }
  
}

class FindIndexLazyIterator 
{
  public static function findIndex<T>(iter:LazyIterator<T>, f:T->Bool):Option<Int>
  {
    return FindIndexIterator.findIndex(iter(), f);
  }
  
}